#!/bin/bash -x 

PROJECTS_DIR="/home/reet/code/github";

function is_git_dir()
{
    param=`find $PWD -name ".git"`;
    if [ -z "$param" ];then
	return 1 #1为假
    else
	return 0 #0为真
    fi    
}

function update_all()
{
    for d in `ls`;
    do
    	if [ -d "$PROJECTS_DIR/$d" ];then
            cd $PROJECTS_DIR/$d ;
	    if is_git_dir $PWD;then
  	    	echo "更新 $PWD   -- "`git pull` >>/tmp/Gitpull-test.log 2>&1 & 

   	    	sleep 5
  	    	echo " (成功)success   "
	    else
		echo "$PWD 不是 git 目录!"
	    fi
	else
	    echo " ..."
	fi
    done
}

cd $PROJECTS_DIR
if [ -z  "$1"  ];then
    update_all
elif [ -d  "$PROJECTS_DIR/$1" ];then
    cd $PROJECTS_DIR/$1
    echo $PWD
else
    echo "not exist \"$PROJECTS_DIR/$1\""
    exit 0;
fi

